package com.le.tester.webpage;

import org.springframework.format.annotation.DateTimeFormat;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;

/**
 * 描述：使用jdk1.8的新特性获取当前的时间
 */
public class DateTimeFor8 {
    public static void main(String[] args) {
        //只获取年月日
        LocalDate localDate = LocalDate.now();
        System.out.println("localDate is " + localDate);
        System.out.println("localDate format is " + localDate.toString().replace("-", "/"));
        System.out.println("=======================");

        //只获取时分秒
        LocalTime localTime = LocalTime.now();
        System.out.println("localTime is " + localTime);
        System.out.println("localTime format is "+localTime.format(DateTimeFormatter.ofPattern("HH:mm:ss")));
        System.out.println("=======================");

        //获取年月日时分秒
        LocalDateTime localDateTime = LocalDateTime.now();
        System.out.println("localDateTime is " + localDateTime);
        System.out.println("localDateTime format is " + localDateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
    }
}
